package com.m3839.sdk.anti.utils;

/**
 * @author ChenBaoyang
 * @description: AntiStringUtils
 * @date 2021/12/8 19:09
 */
public class AntiStringUtils {

    private static final int MINUTE = 60;
    private static final String PLACE_MIN = "%min%";
    private static final String PLACE_SEC = "%sec%";
    private static final String PLACE_TEXT = "%before_start%";

    public static String getPublicTip(int beforeStart, String beforeFormat, String beforeText) {
        int min = getLeftMinuteTime(beforeStart);
        int sec = getLeftSecondTime(beforeStart);
        beforeFormat = beforeFormat.replace(PLACE_MIN, String.valueOf(min));
        beforeFormat = beforeFormat.replace(PLACE_SEC, String.valueOf(sec));
        beforeText = beforeText.replace(PLACE_TEXT, beforeFormat);
        return beforeText;
    }

    /**
     * 获取剩余的分钟数
     *
     * @param time 单位秒
     */
    public static int getLeftMinuteTime(int time) {
        if (time < MINUTE) {
            return 0;
        }
        return time / MINUTE;
    }

    public static int getLeftSecondTime(int time) {
        if (time < MINUTE) {
            return time;
        }
        return time % MINUTE;
    }
}
